home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Explain this> %s \"%[^\"]\"
- Date: 29 Feb 1996 16:59:03 GMT
- Organization: Los Alamos National Laboratory
- Distribution: world
- Message-ID: <TANMOY.96Feb29095903@qcd.lanl.gov>
- References: <4h2t6u$v56@useneta1.news.prodigy.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: DZYS46D@prodigy.com's message of 29 Feb 1996 00:49:34 GMT
-
- In article <4h2t6u$v56@useneta1.news.prodigy.com>
- DZYS46D@prodigy.com (David Cunningham) writes:
- <snip>
- DC:
- DC: I have a file that contains text like this:
- DC:
- DC: 012345678 "Joe Smith"
- DC:
- DC:
- DC: I also have an example of sscanf to pick out these fields. Can someone
- DC: translate what \"%[^\"]\"%d" means. I need to have a good understanding
-
- Nothing. It is not even a complete token :-)
-
- DC: of this for a homework assignment. It looks like this:
- DC:
- DC: sscanf(buff,"%s \ "%[^\"]\" %d",student_list->ss_num,student_list->name);
-
- Nothing. lexical error again. (And if the lexical error were
- corrected, there would have been a programming error: you are telling
- scanf to fill three locations and passing it only two things: I am not
- even sure they have the right type. WHY do people not post a _short_
- complete compilable example: Steve, can the posted copy of the FAQ
- mention it in large bold letters: THOU SHALT NOT LITTER C.L.C. WITH
- ANY FRAGMENT THAT SPEWETH OFF YOUR FINGERS? A lot more bandwidth is
- wasted by improper discussions than by people actually posting code).
-
- If you need to understand the hieroglyphics, first you have to learn
- to reproduce them :-)
-
- Anyway, "%[^\"]\"%d" is a string literal, that is an unmodifiable
- static array of characters containing the following chars:
- '%','[','^','"',']','"','%','d' and '\0'. When sent to scanf it
- encodes the following instructions:
-
- 1) Match (%) the sequence of any characters ([...]) that do not (^)
- contain '"'; and put the result in whatever the first following
- argument points to. Assume that the argument is a pointer to char.
- (If no such character exists, stop).
- 2) Check that the next character is a '"'. If it is not stop. If so,
- discard it.
- 3) Read an integer after skipping over whitespace, and store it in
- whatever the next argument points to. Assume that argument is a
- pointer to int.
- (If an integer is not found, stop)
-
- Return the number of things stored.
-
- "%s \"%[^\"]\" %d" means (in less detail than above):
-
- 1) Means read a sequence of non-whitespace characters and store it in
- the pointer to char passed.
- 2) skip over whitespace
- 3) check and read a following ".
- 4) Read non-" characters and store them in a pointer to char that
- follows.
- 5) check and read a following ".
- 6) skip over blanks.
- 7) skip over blanks and read a decimal integer storing it in the
- pointer to int provided.
-
- Hope this helps
-
- <snip>
- DC: Please explain what these hieroglyphics mean, character by character.
- DC:
- DC: The sscanf will produce this--> 012345678 Joe Smith
- DC:
-
- I do not know any sense in which a sscanf shall produce
- anything. Could you explain?
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-